<template>
  <div id="majorRecommend">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <div class="between">
            <div class="alitem">
              <el-icon @click="onClickBack">
                <ArrowLeftBold />
              </el-icon>
              <span>专业推荐</span>
              <div class="userInfo" style="margin-left: 10px">
                <span>{{ studentData.province }}</span
                >&nbsp; <span>{{ studentData.sex == 0 ? '男' : '女' }}</span
                >&nbsp;
                <!-- <span> {{ studentData.gkaProvinceName }}</span> -->
                <span> {{ studentData.score }}分</span>&nbsp;
                <span> {{ studentData.section || '-' }}位</span>&nbsp;
                <span>{{ studentData.sgname }}</span
                >&nbsp;
                <span>{{ studentData.batch }}</span>
              </div>
            </div>
          </div>
        </div>
      </template>

      <el-scrollbar v-infinite-scroll="load">
        <el-table :data="listData" style="width: 100%">
          <el-table-column prop="year" label="年份" />
          <el-table-column prop="majorName" label="专业名称">
            <template #default="scope">
              <div @click="handleMajor(scope.row)" class="curr">
                {{ scope.row.majorName || '-' }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="percent" label="匹配度">
            <template #default="scope">
              <el-progress :percentage="scope.row.percent" :stroke-width="10" />
            </template>
          </el-table-column> </el-table
      ></el-scrollbar>
    </el-card>
    <Drawertool ref="drawertoolRef" />
  </div>
</template>

<script setup>
import { nextTick, onMounted } from 'vue';
import bus from '@/utils/bus.js';

import Drawertool from '@/components/Drawertool';

import { useRouter, useRoute } from 'vue-router';
import {
  problem,
  // getSelectSearchMajorClassJudge
} from '@/api/appv2/appv2.js';
import { searchMajor } from '@/api/appv2/appv1.js';

const drawertoolRef = ref(null);

const router = useRouter();
const route = useRoute();
const studentData = ref({});
const listData = ref([]);

const handleMajor = (data) => {
  fetcSearchMajor(data);
};
const majorLeavel = ref('');
const fetcSearchMajor = (major) => {
  let data = {
    search: major.majorName,
    code: major.majorCode,
  };
  searchMajor(data).then((res) => {
    console.log(res, 'res');

    if (res.code == 20000) {
      majorLeavel.value = res.data[0].level;
      major.level = majorLeavel.value - 1;

      drawertoolRef.value.handleChangeDrawer(true, '3-1');
      nextTick(() => {
        bus.emit('handleOpenMajorDet', major);
      });
    }
  });
};
// 返回
const onClickBack = () => {
  router.back();
};
const fetchSelectSearchMajorClassJudge = () => {
  problem({
    // sgid: route.query.sgid,
    // studentId: localStorage.getItem('student_id'),
    id: route.query.id,
  }).then((res) => {
    if (res.code == 20000) {
      listData.value = res.data;
      listData.value.sort((a, b) => b.percent - a.percent);
    }
  });
};
onMounted(() => {
  studentData.value = JSON.parse(localStorage.getItem('student_data'));
  fetchSelectSearchMajorClassJudge();
});
const load = () => {};
</script>

<style lang="scss" scoped>
.classifyheader {
  background: #fafafa;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #86909c;
  letter-spacing: 0;
  line-height: 28px;
  padding-right: 80px;

  .sort-sel {
    color: #004cf7;
  }
}

.screen {
  min-height: 50px;
  padding: 6px 0 6px 20px;
  background-color: #f9f9f9;
  display: flex;
  overflow: hidden;
  align-items: center;

  .screenSize {
    font-size: 12px;
    font-weight: 400;
    color: #3d3d3d;
    width: 55px;
  }

  .screenTab {
    padding: 7px 10px;
    margin: 2px 0;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 400;
    color: #4e5969;
    line-height: 14px;
    margin-left: 10px;
  }
}

.box-card {
  margin: 20px;
  width: auto;
  height: calc(100vh - 110px);
  overflow-y: auto;

  .tabs {
    color: #000000;
    font-weight: 600;
    cursor: pointer;
  }

  .active {
    color: #004cf7;
    font-weight: 600;
    cursor: pointer;
  }

  .card-header {
    font-size: 20px;
    font-weight: 600;
    color: #1d2129;
    padding: 10px;

    .userInfo {
      margin-left: 30px;
      font-size: 16px;
      font-weight: 400;
      color: #1d2129;
      line-height: 16px;

      span {
        margin-left: 8px;
      }
    }

    .headerSize {
      color: #4e5969;
      font-size: 14px;
      margin-left: 12px;
      font-weight: 400;
      height: 20px;
      line-height: 21px;
    }
  }
}
</style>

<style>
.el-card__header {
  position: sticky;
  top: 0;
  z-index: 9;
  background-color: white;
}
</style>
